<?php
namespace Library\Model;

class Connexion
{
	use \Library\Traits\Patterns\Singleton;
	
	private static $connexions;
	
	private function __construct()
	{
	}
	
	public static function getListConnexionName()
	{
		if (MOD_TRACE && MOD_TRACE_CLASS_Library_Model_Connexion)
			var_dump("namespace Library\Model; class Connexion -> public static function getListConnexionName()");
		return array_keys(self::$connexions);
	}
	
	public static function getConnexion($connexionName)
	{
		if (MOD_TRACE && MOD_TRACE_CLASS_Library_Model_Connexion)
			var_dump("namespace Library\Model; class Connexion -> public static function getConnexion($connexionName)");
		return self::$connexions[$connexionName];
	}
	
	public static function addConnexion($connexionName, $connexionPDO)
	{
		if (MOD_TRACE && MOD_TRACE_CLASS_Library_Model_Connexion)
			var_dump("namespace Library\Model; class Connexion -> public static function addConnexion($connexionName, \$connexionPDO)");
		self::$connexions[$connexionName] = $connexionPDO;
	}
	
	public static function connectDB(	$host 	= DB_HOST,
										$dbname = DB_NAME,
										$user 	= DB_USER,
										$pass 	= DB_PASS,
										$char 	= DB_CHAR)
	{
		if (MOD_TRACE && MOD_TRACE_CLASS_Library_Model_Connexion)
			var_dump("namespace Library\Model; class Connexion -> public static function connectDB($host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $char 	= DB_CHAR)");
		$db = new \PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
		$db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
		$db->exec("SET CHARACTER SET $char");
		return $db;
	}
}
?>